﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using static System.Net.Mime.MediaTypeNames;

namespace FocusClock.WPF
{
    public class TimeConvertor : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var text = value as string;
            var regext = new Regex(@"^[1-9]\d*$");

            if ((!string.IsNullOrWhiteSpace(text)) && !regext.IsMatch(text))
            {
                return 0;
            }
            else
            {
                int.Parse(text);
            }

            return Binding.DoNothing;
        }
    }
}
